package com.earthea.common.algorithm.dictionarytree;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 字典树节点
 *
 * @param <T> 节点路径类型
 * @param <D> 节点数据类型
 */
@Data
@NoArgsConstructor
public class TreeNode<T, D> {
    /**
     * 字典树节点
     */
    private T item;

    /**
     * 字典树节点数据
     */
    private D data;

    /**
     * 是否是变量
     */
    private boolean variable = false;

    /**
     * 是否前缀匹配
     */
    private boolean prefixMatch = false;

    /**
     * 是否精确匹配
     */
    private boolean match = false;

    /**
     * 子节点
     */
    private Map<T, TreeNode<T, D>> childNodes = new HashMap<>();

    public TreeNode(T item, boolean variable) {
        this.item = item;
        this.variable = variable;
    }

    public TreeNode(T item, boolean variable, boolean prefixMatch) {
        this.item = item;
        this.variable = variable;
        this.prefixMatch = prefixMatch;
    }

    public TreeNode(T item, boolean variable, boolean prefixMatch, D data) {
        this.item = item;
        this.variable = variable;
        this.prefixMatch = prefixMatch;
        this.data = data;
    }
}
